home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / fractals / mandelsquare / mandelsquare-1.06.lha / Iterate.asm < prev    next >
Assembly Source File  |  1992-10-13  |  3KB  |  101 lines

  1. **
  2. **    MandelSquare - AmigaDOS 2.0/3.0 Mandelbrot set explorer
  3. **
  4. **    Iterate.asm, Assembly-language calculation routines
  5. **
  6. **    Copyright © 1991-1992 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9.  
  10.     csect    text,0,0,1,2
  11.  
  12.     xdef    _Iterate
  13.  
  14. ;    UBYTE Iterate(double RealValue,double ImaginaryValue);
  15. ;
  16. ;        Fast hand-coded '881 assembly language subroutine.
  17. ;    As SAS/C 5.10b and apparently all of its predecessors fail
  18. ;    to correctly pass the function arguments in fpu registers
  19. ;    SAS/C v6.0 or higher is required to compile the program.
  20. ;
  21. ;    This is ye olde z²+c algorithm, register usage is a follows:
  22. ;
  23. ;        d0    = Maximum number of iterations to run
  24. ;        d1    = Number of iterations actually run
  25. ;
  26. ;        fp0    = c (real component, constant)
  27. ;        fp1    = c (imaginary component, constant)
  28. ;
  29. ;        fp2    = Real component
  30. ;        fp3    = Imaginary component
  31. ;
  32. ;        fp4    = z (real component, scratch)
  33. ;        fp5    = z (imaginary component, scratch)
  34. ;
  35. ;        fp6    = Scratch
  36.  
  37. _Iterate:
  38.  
  39.     fmovem.x fp2-fp6,-(sp)            ; Save registers
  40.  
  41.     fmove.x    fp0,fp2                ; Real = RealValue
  42.     fmove.x    fp1,fp3                ; Imaginary = ImaginaryValue
  43.  
  44.     move.l    _MaxIteration(a4),d0        ; Get maximum number of iterations
  45.     moveq    #1,d1                ; i = 1
  46.  
  47.     fmove.x    fp2,fp4                ; RealTemp = Real
  48.     fmove.x    fp3,fp5                ; ImaginaryTemp = Imaginary
  49.  
  50.     fmul.x    fp4,fp4                ; RealTemp = RealTemp^2
  51.     fmul.x    fp5,fp5                ; ImaginaryTemp = ImaginaryTemp^2
  52.  
  53.     fmove.x    fp4,fp6                ; Scratch  = RealTemp
  54.     fadd.x    fp5,fp6                ; Scratch += ImaginaryTemp
  55.     fabs.x    fp6,fp6                ; Scratch  = fabs(Scratch)
  56.  
  57.     fcmp.w    #4,fp6                ; Scratch > 4?
  58.     fbgt.w    2$                ; true -> break
  59.  
  60. 1$    fadd.x    fp3,fp3                ; Imaginary *= 2
  61.     fmul.x    fp2,fp3                ; Imaginary *= Real
  62.     fadd.x    fp1,fp3                ; Imaginary += ImaginaryValue
  63.  
  64.     fmove.x    fp4,fp2                ; Real = RealTemp
  65.     fsub.x    fp5,fp2                ; Real -= ImaginaryTemp
  66.     fadd.x    fp0,fp2                ; Real += RealValue
  67.  
  68.     fmove.x    fp2,fp4                ; RealTemp = Real
  69.     fmove.x    fp3,fp5                ; ImaginaryTemp = Imaginary
  70.  
  71.     fmul.x    fp4,fp4                ; RealTemp = RealTemp^2
  72.     fmul.x    fp5,fp5                ; ImaginaryTemp = ImaginaryTemp^2
  73.  
  74.     fmove.x    fp4,fp6                ; Scratch  = RealTemp
  75.     fadd.x    fp5,fp6                ; Scratch += ImaginaryTemp
  76.     fabs.x    fp6,fp6                ; Scratch  = fabs(Scratch)
  77.  
  78.     fcmp.w    #4,fp6                ; Scratch > 4?
  79.     fbgt.w    2$                ; true -> break
  80.  
  81.     addq    #1,d1                ; Iterations++;
  82.     dbf    d0,1$                ; false -> Loop;
  83.  
  84.     moveq    #0,d0
  85.  
  86.     fmovem.x (sp)+,fp2-fp6            ; Restore registers, return 0
  87.     rts
  88.  
  89. 2$    movea.l    _Wave(a4),a0            ; Get colour wave table
  90.     move.b    0(a0,d1.w),d0            ; Get wave index, always > 0
  91.  
  92.     fmovem.x (sp)+,fp2-fp6            ; Restore registers
  93.     rts
  94.  
  95.     section    __MERGED,data
  96.  
  97.     xref    _MaxIteration
  98.     xref    _Wave
  99.  
  100.     end
  101.